#include "Completer.h"
#include <QStringList>
#include "common.h"

//-------------------------------------

Completer::Completer(QObject *parent) :
    QCompleter(parent)
{
    separator = QLatin1String( DOT );
    setCompletionMode( QCompleter::PopupCompletion );
    setCaseSensitivity( Qt::CaseSensitive );
}

//-------------------------------------

QStringList Completer::splitPath( const QString & path ) const
{
    if( separator.isNull() )
        return QCompleter::splitPath( path );

    return path.split( separator );
}

//-------------------------------------

QString Completer::pathFromIndex( const QModelIndex & index ) const
{
    if( separator.isNull() )
        return QCompleter::pathFromIndex( index );

    QStringList sl;
    for( QModelIndex i = index; i.isValid(); i = i.parent() )
        sl.prepend( model()->data( i, completionRole() ).toString() );

    return sl.join( separator );
}

//-------------------------------------

